/////////////////
//  PREAMBLE  //
////////////////


/*	program:	Analysis-6-State-Expenditures-Revenue.do
	author:		David Bateman */

/******************************************************************************/
/***                                                                        ***/
/*** File uses the Sylla et al. (2006) data on state expenditures and       ***/
/*** revenued to evalute the impact of suffrage qualification changes on    ***/
/*** state policy. The data is from ICPSR 09728. It is not included in      ***/
/*** the replication files but is easily accessible on ICPSR's website. The ***/
/*** initial manipulation of the data is commented out below. This produces ***/
/*** a file including all states' expenditures/revenues. This file is       ***/
/*** included in the replication data.                                      ***/
/***                                                                        ***/
/******************************************************************************/

cd "..\..\Dataverse\"
set more off

/*
*** The following lines of code open the different Sylla et al. files and 
*** append them into a single file with all observations for all states. The 
*** appended file has been saved for ease of analysis. The ICPSR-098728 files have
*** not been included in the replication material but are available through the ICPSR
*** website.

*** The Sylla et al. files include 3 tables. Each is at a separate level of aggregation.
*** The third level of aggregation (3-digit codes) is the most precise but also has the
*** least consistent coverage and most errors in coding (according to the Sylla et al. 
*** codebooks. 

global DS
qui forvalues i = 1(1)94 {
	global DS ${DS} `i' 
}

qui foreach x in $DS {
	if `x'>=100 {
		*** This is included only for consistency. The 97-100 files are examples.
		clear
		import delimited using "Data\ICPSR_09728\DS0`x'\09728-0`x'-Data.txt"
		capture destring v4, force replace
		gen v5 = `x'
		tempfile save`x'
		save `save`x'', replace
	}
	else if `x'<100 & `x'>=10 {
		clear
		import delimited "Data\ICPSR_09728\DS00`x'\09728-00`x'-Data.txt"
		capture destring v4, force replace
		gen v5 = `x'
		tempfile save`x'
		save `save`x'', replace
	}
	else if `x'<10 {
		clear
		import delimited "Data\ICPSR_09728\DS000`x'\09728-000`x'-Data.txt"
		capture destring v4, force replace
		gen v5 = `x'
		tempfile save`x'
		save `save`x'', replace
	}
}
 
use `save1'
forvalues i = 2(1)94 {
append using `save`i'', force
drop if v2==. & v3==.
}


rename v1 state
rename v2 year
rename v3 code
rename v4 amount
rename v5 source_file

label variable state "State Abbreviation"
label variable year "Year"
label variable code "The ISO code from Sylla et (2006) (revenue/expenditure"
label variable amount "Amount"
label variable source_file "Sylla et al source file"

label data "Appended Sylla et al. files (ICPSR_09728)"

*** Save the appended file for ease of analysis.
save "Data\expenditures-revenue.dta", replace
*/

 
use "Data\expenditures-revenue.dta", clear


*** Drop some miscodings / ambiguous codings that can't be corrected.
*** This includes Missouri's (and a few other states) four digit codes.
drop if code >=1000 & code!=.
drop if code==0 & amount==.
*** Identify the different data "tables" - 1 digit, 2 digit, 3 digits
gen table = 3 if code>=100 & code<=999
*** Some codes were rounded incorrectly in initial dataset. Identify these as 
*** occuring in the appropriate table where this is the case. 
replace table = 3 if table==. & table[_n-1]==3 & table[_n+1]==3
replace table = 3 if table==. & table[_n-2]==3 & table[_n+2]==3
replace table = 2 if code>=10 & code<=99 & table==.
replace table = 2 if table==. & table[_n-1]==2 & table[_n+1]==2
replace table = 2 if table==. & table[_n-2]==2 & table[_n+2]==2
replace table = 1 if code>=1 & code<=9 & table==.
replace table = 1 if table==. & table[_n-1]==1 & table[_n+1]==1
replace table = 1 if table==. & table[_n-2]==1 & table[_n+2]==1
drop if table == 3

*** Correct table for RI and NE, where code is 0
replace table = 2 if code==0 & source_file == 33 & table[_n+1]==2
replace table = 2 if code==0 & source_file == 48 & table[_n-1]==2


*** Create icpsrstate code 
*** Some of the state abbreviations are unconventional. The manifest lists AK as
*** Alaska, but given the time period it is clearly mistaken. It is more plausible 
*** that it is Arkansas, with the state appearing in the data only two years after
*** becoming a state.
replace state 		= "AR" if state=="AK"
replace state 		= "IA" if state=="IO"
replace state 		= "KS" if state=="KA"
replace state 		= "MS" if state=="MIS"

gen icpsrstate		= 1 if state == "CT"
replace icpsrstate 	= 2 if state == "ME"
replace icpsrstate 	= 3 if state == "MA"
replace icpsrstate 	= 4 if state == "NH"
replace icpsrstate 	= 5 if state == "RI"
replace icpsrstate 	= 6 if state == "VT"
replace icpsrstate 	= 11 if state == "DE"
replace icpsrstate 	= 12 if state == "NJ"
replace icpsrstate 	= 13 if state == "NY"
replace icpsrstate 	= 14 if state == "PA"
replace icpsrstate 	= 21 if state == "IL"
replace icpsrstate 	= 22 if state == "IN"
replace icpsrstate 	= 23 if state == "MI"
replace icpsrstate 	= 24 if state == "OH"
replace icpsrstate 	= 25 if state == "WI"
replace icpsrstate 	= 31 if state == "IA"
replace icpsrstate 	= 32 if state == "KS"
replace icpsrstate 	= 33 if state == "MN"
replace icpsrstate 	= 34 if state == "MO"
replace icpsrstate 	= 35 if state == "NE"
replace icpsrstate 	= 36 if state == "ND"
replace icpsrstate 	= 37 if state == "SD"
replace icpsrstate 	= 40 if state == "VA"
replace icpsrstate 	= 41 if state == "AL"
replace icpsrstate 	= 42 if state == "AR"
replace icpsrstate 	= 43 if state == "FL"
replace icpsrstate 	= 44 if state == "GA"
replace icpsrstate 	= 45 if state == "LA"
replace icpsrstate 	= 46 if state == "MS"
replace icpsrstate 	= 47 if state == "NC"
replace icpsrstate 	= 48 if state == "SC"
replace icpsrstate 	= 49 if state == "TX"
replace icpsrstate 	= 51 if state == "KY"
replace icpsrstate 	= 52 if state == "MD"
replace icpsrstate 	= 53 if state == "OK"
replace icpsrstate 	= 54 if state == "TN"
replace icpsrstate 	= 55 if state == "DC"
replace icpsrstate 	= 56 if state == "WV"
replace icpsrstate 	= 61 if state == "AZ"
replace icpsrstate 	= 62 if state == "CO"
replace icpsrstate 	= 63 if state == "ID"
replace icpsrstate 	= 64 if state == "MT"
replace icpsrstate 	= 65 if state == "NV"
replace icpsrstate 	= 66 if state == "MN"
replace icpsrstate 	= 67 if state == "UT"
replace icpsrstate 	= 68 if state == "WY"
replace icpsrstate 	= 71 if state == "CA"
replace icpsrstate 	= 72 if state == "OR"
replace icpsrstate 	= 73 if state == "WA"
replace icpsrstate 	= 81 if state == "AK"
replace icpsrstate 	= 82 if state == "HI"

*** Merge in total population and rate of growth from census file
merge m:1 icpsrstate year using "Data\adult-male-census-states.dta" , keepusing(totpop growth statefip)
drop if _merge!=3
drop _merge
keep if year<=1860

label variable state "State abbreviation"
label variable year "Year"
label variable code "Revenue/Expenditure code"
label variable amount "Amount of revenue/expenditure"
label variable source_file "Which ICPSR file does observation come from"
label variable icpsrstate "ICPSR state code"

label define code 1 "Revenue----Total" 10 "Tax Revenue" 11 "Property Tax" 12 "Special Tax" 13 "Income Tax" 14 "Other Business Taxes" 15 "Sales Tax" 16 "Other Special Taxes" 17 "Poll Tax" 18 "Licenses and Permits" 19 "Other Taxes"
label define code 20 "Non Tax Revenue"  21 "Special Assessments" 22 "Fines etc" 23 "Subventions" 24 "Donations etc" 25 "Highways" 26 "Earnings of Depts" 27 "Earnings of Public Service Enterprises" 28 "Insurance Trust Revenue" 29 "Charges and misc.", add
label define code 3 "Expenditures----Total"  31 "Education" 32 "Social Services" 33 "Transportation" 34 "Public Safety" 35 "Environmental" 36 "Govt Admin" 37 "Public Service Expend" 38 "Insurance Trust Expend" 39 "Not Classified" 40 "Interest on Debt" 41 "Sinking Fund", add
label values code code

*** A few states (most important RI) have obvious mistakes in its codes. A revenue category is given as
*** 0, but clearly aggregates to total revenue. It appears in both the 2-digit and 3-digit
*** classifications. On inspection, I believe it is tax revenue (10). When it is in expenditures
*** I reclassify as "Not Classified"
replace code = 10 if code==0 & source_file==47
replace code = 39 if code==0 & source_file==48
replace code = 30 if code==0 & source_file==18
*** In WI, the 0 code is the same as the total revenue. 
drop if code==0 & source_file==92

*** Other states have what initially seem to be expenditures or revenue codings in the 
*** wrong tables. They are not mistaken entries (ie., when in revenue file they are revenue). 
*** They are miscodings or idiosyncratic codings. There are not many so I drop them.

*** Revenue with a code that implies expenditures
drop if (code>=30 & code<=49) & source_file==47 
drop if (code>=30 & code<=49) & source_file==10
drop if (code>=30 & code<=49) & source_file==20
drop if (code>=30 & code<=49) & source_file==41
drop if (code>=30 & code<=49) & source_file==29
drop if (code>=30 & code<=49) & source_file==49
*** Order of the files (revenue/expenditures) changed with 65 part.
drop if (code>=30 & code<=49) & source_file==92
drop if (code>=30 & code<=49) & source_file==72
*** Expenditure with a code that implies revenues.
drop if (code>=10 & code<=29) & source_file==48
drop if (code>=10 & code<=29) & source_file==11
drop if (code>=10 & code<=29) & source_file==21
drop if (code>=10 & code<=29) & source_file==42
drop if (code>=10 & code<=29) & source_file==30
drop if (code>=10 & code<=29) & source_file==50
*** Order of the files (revenue/expenditures) changed with 65 part.
drop if (code>=10 & code<=29) & source_file==91
drop if (code>=10 & code<=29) & source_file==71
*** Kentucky has a misclassified code in the table 1 revenue. This should be
*** unclassified (39) in table 2
replace code = 39 if source_file==79 & code==3 & amount<=10000 & year==1849
*** Make sure all remaining zero codes are dropped.
drop if code==0
*** A few states have duplicate observations. Drop them
duplicates drop code state year amount table, force
sort state year source code 
*** Drop transfers and unknown
drop if code>=60 & code<=99
*** Where there are now multiple unclassified amounts in a year, replace these their sum
duplicates list state year code
qui summ amount if year==1849 & source_file==79 & code==39
loc sum = r(sum)
replace amount = `sum' if year==1849 & source_file==79 & code==39 & _n==3018
qui summ amount if year==1859 & source_file==48 & code==39
loc sum = r(sum)
replace amount = `sum' if year==1859 & source_file==48 & code==39 & _n==11386

****************** 		Create analytical variables 		********************
*** Per capita amounts
gen per_cap = amount/totpop

qui levelsof state, local(states)
*** For informational purpose, identify which codes are present in which states
foreach x in `states' {
	di "Codes present in `x'"
	levelsof code if state=="`x'"
}

*** Create yearly tax and non-tax revenues and total revenue/expenditures
*** Most states did not receive the 20 non-tax revenue codings. Some states have 
*** this code but then also have additional non-tax revenue that is clearly not
*** included in the 20 code category. The best approach is to add all the non-tax
*** revenue categories.
tempvar a b c d
bys state year: egen `a' = total(amount) if code>=10 & code<=19
bys state year: egen `b' = total(amount) if code>=20 & code<=29
bys state year: egen tax_rev 	= mean(`a')
bys state year: egen nontax_rev	= mean(`b')

bys state year: egen `c' = total(amount) if code==1
bys state year: egen `d' = total(amount) if code==3
bys state year: egen revenue 	= mean(`c')
bys state year: egen expendit	= mean(`d')

*** Create a year/state ID variable
egen id = group(icpsrstate year)

*** Different measures of how much revenue is generated by taxation. The second 
*** will likely be more accurate, because it doesn't exclude 2-digit categories 
*** that were dropped above.
gen pertax1_	= round(tax_rev/(tax_rev+nontax_rev)*100,0.01)
gen pertax2_	= round(tax_rev/amount*100,0.01) if code==1

duplicates drop state year code, force
drop amount source_file table
capture drop _*

*** Reshape data to facilitate cross-sectional analysis
reshape wide per_cap tax_rev nontax_rev pertax1_ pertax2_ revenue expendit, i(id) j(code)

*** Rename variables, drop unnecessary ones created during reshape process, and create new variables
rename tax_rev1 taxrev
rename nontax_rev1 nontaxrev
rename pertax1_1 pertax1 
rename pertax2_1 pertax2
rename revenue1 rev
rename expendit1 exp
drop tax_rev* nontax_rev* pertax*_* revenue* expendit*

gen deficit 	= rev-exp
gen percap_def	= deficit/totpop
*** Log per capita revenue and expenditures to capture the growth of the economies
gen logrev		= log(per_cap1)
gen logexp		= log(per_cap3)

*** Gen % of budget on education, social services, infrastructure, govt ops	
gen pereduc		= round((per_cap31/per_cap3)*100,0.01)
gen perinfra	= round((per_cap33/per_cap3)*100,0.01)
gen persafety	= round((per_cap34/per_cap3)*100,0.01)
gen pergovt		= round((per_cap36/per_cap3)*100,0.01)

*** Gen log per capita on education, social services, infrastructure, govt ops	
gen logeduc		= log(per_cap31)
gen loginfra	= log(per_cap33)
gen logsafety	= log(per_cap34)
gen loggovt		= log(per_cap36)

label variable taxrev "Revenue from taxation"
label variable nontaxrev "Revenue from non-tax sources"
label variable pertax1 "% of tax+non-tax revenues raised by taxes"
label variable pertax2 "% of total revenues raised by taxes"
label variable rev "Revenue"
label variable exp "Expenditures"
label variable deficit "Deficit (not reported but calculated)"
label variable percap_def "Deficit per capita"
label variable logrev "Log per capita revenue"
label variable logexp "Log per capita expenditures"
label variable pereduc "Education as percent of total expenditures"
label variable perinfra "Infrastructure as percent of total expenditures"
label variable persafety "Public Safety as percent of total expenditures"
label variable pergovt "Government administration as percent of total expenditures"

label variable logeduc "Log education spending per capita"
label variable loginfra "Log infrastructure spending per capita"
label variable logsafety "Log public safety spending per capita"
label variable loggovt "Log government administration spending per capita"

*** Create missing rows
tsset icpsrstate year
tsfill, full

*** Identify years where there was a war
gen war=1 if year>=1812 & year<=1814
replace war 	= 1 if year>=1846 & year<=1848
replace war 	= 0 if war!=1

*** The federal government disbursed the federal surplus to the states. It was
*** a windfall for state government revenues.
gen disbursement = year>=1837 & year<=1838

*** Create date variables.
gen date 	= "12/31/"+string(year)
gen date1	= date(date, "MDY")
gen decade 	= int(year/10)*10

*** When did suffrage reform go into effect?
gen reform 		= . 
replace reform	= -61197 if state=="DE" 
replace reform	= -57351 if state=="MD" 
replace reform	= -55563 if state=="NJ" 
replace reform	= -54434 if state=="SC" 
replace reform	= -51683 if state=="CT" 
replace reform	= -50618 if state=="MA" 
replace reform	= -50344 if state=="NY" 
replace reform	= -47361 if state=="VA" 
replace reform	= -42643 if state=="RI" 
replace reform	= -41637 if state=="LA"
replace reform	= -37365 if state=="NC"

gen category 	 = 1 if (date1<-61197) & icpsrstate==11	// Constitution goes into effect on June 12, 1792.
replace category = 1 if (date1<-57351) & icpsrstate==52 // Amendment passed second time on 23rd Dec 1803
replace category = 1 if (date1<-55563) & icpsrstate==12	// Statute altering qualifications enacted on Nov 16 - "from and after the passing of this act."
replace category = 2 if (date1<-54434) & icpsrstate==48	// Constitutional amendment ratified on December 19, 1810.
replace category = 1 if (date1<-51585) & icpsrstate==1 	// Constitution ratified on first Monday of Oct 1818. In Nov. 1817 a modification of the existing election law was passed, repealing the "stand-up" law. A constitutional convention would be called in 1818 on a broad franchise.
replace category = 1 if (date1<-50618) & icpsrstate==3 	// Constitutional amendments ratified in April/May of 1821. Presented to General Court on May 31 and certified May 24
replace category = 2 if (date1<-50344) & icpsrstate==13	// Constitution ratified in January 1822 and went into effect on Dec 31 1822. Suffrage went into effect 1st Monday of March 1822
replace category = 1 if (date1<-39800) & icpsrstate==40 // Constitution went into effect on January 12, 1851
replace category = 2 if (date1<-47300) & icpsrstate==40 // Constitution ratified and went into effect on July 1 1830
replace category = 2 if (date1<-42643) & icpsrstate==5	// Constitution went into effect in May 1843
replace category = 1 if (date1>=-42643) & icpsrstate==5	// Constitution went into effect in May 1843
replace category = 1 if (date1<-41637) & icpsrstate==45	// Constitution went into effect in January 1846
replace category = 2 if (date1<-37365) & icpsrstate==47	// Governor proclaimed results of referendum on Sept 12 1857
replace category = 0 if category==.

*** Create an alternate categorization of franchise qualifications in which the
*** high/medium categories are collapsed.
gen alt_cat		= 1 if (date1<-61197) & icpsrstate==11	// Constitution goes into effect on June 12, 1792.
replace alt_cat	= 1 if (date1<-57351) & icpsrstate==52 	// Amendment passed second time on 23rd Dec 1803
replace alt_cat	= 1 if (date1<-55563) & icpsrstate==12	// Statute altering qualifications enacted on Nov 16 - "from and after the passing of this act."
replace alt_cat = 1 if (date1<-54434) & icpsrstate==48	// Constitutional amendment ratified on December 19, 1810.
replace alt_cat = 1 if (date1<-51585) & icpsrstate==1 	// Constitution ratified on first Monday of Oct 1818. In Nov. 1817 a modification of the existing election law was passed, repealing the "stand-up" law. A constitutional convention would be called in 1818 on a broad franchise.
replace alt_cat = 1 if (date1<-50618) & icpsrstate==3 	// Constitutional amendments ratified in April/May of 1821. Presented to General Court on May 31 and certified May 24
replace alt_cat = 1 if (date1<-50344) & icpsrstate==13	// Constitution ratified in January 1822 and went into effect on Dec 31 1822. Suffrage went into effect 1st Monday of March 1822
*** Treat Virginia as going from 1->0 in 1830
replace alt_cat = 0 if (date1<-39800) & icpsrstate==40 	// Constitution went into effect on January 12, 1851
replace alt_cat = 1 if (date1<-47300) & icpsrstate==40 	// Constitution ratified and went into effect on July 1 1830
*** Treat Rhode Island as going from 1->0 in 1843
replace alt_cat = 1 if (date1<-42643) & icpsrstate==5	// Constitution went into effect in May 1843
replace alt_cat = 0 if (date1>=-42643) & icpsrstate==5	// Constitution went into effect in May 1843
replace alt_cat = 1 if (date1<-41637) & icpsrstate==45	// Constitution went into effect in January 1846
replace alt_cat = 1 if (date1<-37365) & icpsrstate==47	// Governor proclaimed results of referendum on Sept 12 1857
replace alt_cat = 0 if alt_cat==.

*************************	Analyses	****************************************
xtset icpsrstate year
eststo main_1: xtreg F1.logrev i.alt_cat i.disbursement i.war year, fe robust
estadd local ctrls "Yes"
estadd local fixed "State"
eststo main_2: xtreg F1.logexp i.alt_cat i.disbursement i.war year, fe robust
estadd local ctrls "Yes"
estadd local fixed "State"
eststo main_3: xtreg F1.pertax2 i.alt_cat i.disbursement i.war year, fe robust
estadd local ctrls "Yes"
estadd local fixed "State"
eststo main_4: xtreg F1.pereduc i.alt_cat i.disbursement i.war year, fe robust
estadd local ctrls "Yes"
estadd local fixed "State"
eststo main_5: xtreg F1.perinfra i.alt_cat i.disbursement i.war year, fe robust
estadd local ctrls "Yes"
estadd local fixed "State"
eststo main_6: xtreg F1.persafety i.alt_cat i.disbursement i.war year, fe robust
estadd local ctrls "Yes"
estadd local fixed "State"

*** Supplemental analyses. Use the other measure of % tax and use the log per capita
*** values for spending. Also examine the effect of suffrage reform on the 
*** lagged outcome (forward looking treatment) of percent tax. 
eststo suppl_1: xtreg F1.pertax1 i.alt_cat i.disbursement i.war year, fe robust
estadd local ctrls "Yes"
estadd local fixed "State"
eststo suppl_2: xtreg L3.pertax2 i.alt_cat i.disbursement i.war year, fe robust
estadd local ctrls "Yes"
estadd local fixed "State"
eststo suppl_3: xtreg F1.logeduc i.alt_cat i.disbursement i.war year, fe robust
estadd local ctrls "Yes"
estadd local fixed "State"
eststo suppl_4: xtreg F1.loginfra i.alt_cat i.disbursement i.war year, fe robust
estadd local ctrls "Yes"
estadd local fixed "State"
eststo suppl_5: xtreg F1.logsafety i.alt_cat i.disbursement i.war year, fe robust
estadd local ctrls "Yes"
estadd local fixed "State"


*** Create figures for main text and supplemental material
*** First identify for which of the reforming states we have aggregate revenue/
*** expenditures data before and after reform. 
gen refState = icpsrstate==11 | icpsrstate==52 | icpsrstate==12 | icpsrstate==48 | icpsrstate==1 | icpsrstate==3 | icpsrstate==13 | icpsrstate==40 | icpsrstate==5 | icpsrstate==45 | icpsrstate==47
qui levelsof icpsrstate if refState==1, local(refState)
foreach x in `refState' {
	foreach y in logrev logexp {
		qui summ year if icpsrstate==`x' & alt_cat==0
		local k = r(min)
		qui summ logrev if year>`k' & icpsrstate==`x'
		local post = r(mean)
		qui summ logrev if year<=`k' & icpsrstate==`x'
		local pre = r(mean)
		if `pre'!=. & `post'!=. & "`y'"=="logrev" {
			di in green "There is pre-/post-reform revenue data for state " in yellow "`x'"
		}
		else if  `pre'!=. & `post'!=. & "`y'"=="logexp" {
			di in green "There is pre-/post-reform expenditure data for state " in yellow "`x'"		
		}
	}
}
gen revState = icpsrstate==1 | icpsrstate==48 | icpsrstate==5 | icpsrstate==47 | icpsrstate==13 | icpsrstate==40
gen expState = icpsrstate==1 | icpsrstate==48 | icpsrstate==5 | icpsrstate==47 | icpsrstate==13 | icpsrstate==40
*** Log per capita revenue/expenditure in the reforming states for which we have data.
foreach z in revState expState {
	qui levelsof state if `z'==1, local(state)
	
	if "`z'" == "revState" {
		loc v = "logrev"
	}
	else if "`z'" == "expState" {
		loc v = "logexp"
	}
	foreach x in `state' {
		summ year if state=="`x'" & alt_cat==0
		local k = r(min)

		if "`x'" == "VA" {
			tw 	(lpolyci `v' year if year<1830 & state=="`x'", clcol(black))	///
				(lpolyci `v' year if year>=1830 & year<1850 & state=="`x'", clcol(black))	///
				(lpolyci `v' year if year>=1851 & state=="`x'", clcol(black))	///
				(scatter `v' year if state=="`x'", msy(o) jitter(.5) mc(gs6)  mlw(vvvthin) mlc(gs6) ),	///
					xline(1830 1851, lw(thin) lp(dash) lc(black)) 				///
					graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) ylabel(none, angle(h) labsize(vsmall) nogrid) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`v'_`x'", replace)

		}
		else {
			tw 	(lpolyci `v' year if alt_cat==1 & state=="`x'", clcol(black))	///
				(lpolyci `v' year if alt_cat==0 & state=="`x'", clcol(black))	///
				(scatter `v' year if state=="`x'", msy(o) jitter(.5) mc(gs6)  mlw(vvvthin) mlc(gs6) ),	///
				xline(`k', lw(thin) lp(dash) lc(black))	xlabel(, labsize(vsmall))			///
						graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) ylabel(none, angle(h) labsize(vsmall) nogrid) ///
							title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`v'_`x'", replace)
		}
						
	}
}

*** Create a plot showing the change in revenue for ten years 
gen reform_year = year(reform)
replace reform_year = 1850 if refState==0
bys state (year): gen alt_year = year-reform_year

tw lpolyci logrev alt_year if refState==1 & revState==1 & alt_year>=-20 & alt_year<=20, bw(1) cmissing(n) clc(black) xline(0, lc(black) lp(dash))	///
	, graphreg(col(none)) legend(off)	///
	xtitle("Years from Reform", size(small)) xlab(, labsize(small)) ylab(, nogrid angle(h) labsize(small)) 	///
	title("Revenues", size(small) col(black)) name(revenue_reform, replace)

tw lpolyci logexp alt_year if refState==1 & expState==1 & alt_year>=-20 & alt_year<=20, bw(1) cmissing(n) clc(black) xline(0, lc(black) lp(dash))	///
	, graphreg(col(none)) legend(off)	///
	xtitle("Years from Reform", size(small)) xlab(, labsize(small)) ylab(, nogrid angle(h) labsize(small)) 	///
	title("Expenditures", size(small) col(black)) name(expenditures_reform, replace)

*** For Figure 8 include Rhode Island as a medium state after 1843 rather than a low state.
*** The statistical analyses for this section collapse the medium/high categories. But there is no
*** need to display it that way.
replace alt_cat = 1 if (date1>=-42643) & icpsrstate==5	// Constitution went into effect in May 1843
tw lpolyci logrev year if alt_cat==1, bw(1) cmissing(n) clc(black)   ///
	|| lpolyci logrev year if alt_cat==0, bw(1) cmissing(n) alc(black) alw(vthin) fc(none) clc(black) lp(dash) alp(solid)	///
	, graphreg(col(none)) legend(order(2 4) label(2 "Medium/High") label(4 "Low") size(small))	///
	xtitle("", size(small)) xlab(1785(15)1860, labsize(small)) ylab(, nogrid angle(h) labsize(small)) 	///
	title("Revenues", size(small) col(black)) name(graph_rev, replace)
tw lpolyci logexp year if alt_cat==1, bw(1) cmissing(n) clc(black)   ///
	|| lpolyci logexp year if alt_cat==0, bw(1) cmissing(n) alc(black) alw(vthin) fc(none) clc(black) lp(dash) alp(solid)	///
	, graphreg(col(none)) legend(order(2 4) label(2 "Medium/High") label(4 "Low") size(small))	///
	xtitle("", size(small)) xlab(1785(15)1860, labsize(small)) ylab(, nogrid angle(h) labsize(small)) 	///
	title("Expenditures", size(small) col(black)) name(graph_exp, replace)
tw lpolyci percap_def year if alt_cat==1, bw(1) cmissing(n) clc(black)   ///
	|| lpolyci percap_def year if alt_cat==0, bw(1) cmissing(n) alc(black) alw(vthin) fc(none) clc(black) lp(dash) alp(solid)	///
	, graphreg(col(none)) legend(order(2 4) label(2 "Medium/High") label(4 "Low") size(small)) yline(0, lc(black) lw(thin)) ///
	xtitle("", size(small)) xlab(1785(15)1860, labsize(small)) ylab(, nogrid angle(h) labsize(small)) 	///
	title("Deficit", size(small) col(black)) name(graph_def, replace)
*** Return RI to collapsed medium/high coding
replace alt_cat = 0 if (date1>=-42643) & icpsrstate==5	// Constitution went into effect in May 1843

********************************************************************************
**************	 Create Tables and Combine Figures 	  **************************
********************************************************************************
****************				Main Text 				************************

*** Table 8: Franchise Qualifications and State Revenues / Expenditures
esttab main_1 main_2 main_3 using "Tables/Table-8.tex", se(a2)  label 	///
	title(Franchise Qualifications and State Revenues and Expenditures) 	///
	drop( _cons 0*.alt_cat *disbursement *war *year ) nonumbers 	///
	coeflabels(1.alt_cat "High/Medium Threshold ($\beta$)")	///
	mgroups("Log Per Capita" "Log Per Capita" "Percent of Revenue" , pattern(1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span )         ///
	mtitles("Revenue" "Expenditures" "From Taxes" )				///
	nogaps nodepvars nostar compress noconstant nonotes	 		///
	stats(ctrls fixed N_g N, fmt(%9.0g) label("Additional controls" "Fixed effects" "States" "N")) b(a3) 						///
	nolines prehead(\begin{table}[hbt!]\centering 	\caption{@title} \label{tab:8} \begin{tabular}{l*{4}{c}} \toprule)		///		
	posthead(\midrule)  prefoot(\midrule) ///
	substitute(\_ _) tex  fragment replace	
esttab main_4 main_5 main_6 using "Tables/Table-8.tex", se(a2)  label 	///
	title(Franchise Qualifications and State Revenues and Expenditures) 	///
	drop( _cons 0*.alt_cat *disbursement *war *year ) nonumbers 	///
	coeflabels(1.alt_cat "High/Medium Threshold ($\beta$)")	///
	mgroups("Percent of Total Expenditures" , pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span )         ///
	mtitles("Education" "Infrastructure" "Public Safety")				///
	nogaps nodepvars nostar compress noconstant nonotes	 		///
	stats(ctrls fixed N_g N, fmt(%9.0g) label("Additional controls" "Fixed effects" "States" "N")) b(a3) 						///
	nolines prehead(\toprule)	///		
	posthead(\midrule)  prefoot(\midrule) ///
	postfoot(\bottomrule \multicolumn{@span}{p{.8\textwidth}}{\footnotesize Robust standard errors. Controls for Surplus Revenue disbursement, war, and time trend included in all models. All treatment and conditioning variables lagged by one year.}	///
	\end{tabular} \end{table}) substitute(\_ _) tex  fragment append		


*** Figure 8: Aggregate patterns in states' revenues / expenditures	
grc1leg graph_rev graph_exp , cols(2) graphreg(col(white)) imargin(tiny) l1title("Log Per Capita", size(vsmall)) ycommon name(rev_exp, replace)
graph combine revenue_reform expenditures_reform , cols(2) graphreg(col(white)) imargin(tiny) l1title("Log Per Capita", size(vsmall)) ycommon name(rev_exp_reform, replace)
graph combine rev_exp rev_exp_reform, rows(2) graphreg(col(white)) imargin(tiny) 

graph export "Figures\Figure-8.pdf", replace 

*******************		Supplemental Material 		****************************

*** Table A19: Alternative specifications of revenues and expenditures.
esttab suppl_1 suppl_2 suppl_3 suppl_4 suppl_5  using "Tables/Supplemental/Supplemental-Table-19.tex", se(a2)  label 	///
	title(Alternative specifications of franchise qualifications and state revenues and expenditures) 	///
	drop( _cons 0*.alt_cat *disbursement *war *year ) nonumbers 	///
	coeflabels(1.alt_cat "High/Medium ($\beta$)")	///
	mgroups("Revenue from taxes" "Log per capita spending" , pattern(1 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span )         ///
	mtitles("Alt. measure" "Lag. 3 years" "Education" "Infrastructure" "Public Safety" )				///
	nogaps nodepvars nostar compress noconstant nonotes	 		///
	stats(ctrls fixed N_g N, fmt(%9.0g) label("Additional controls" "Fixed effects" "States" "N")) b(a3) 						///
	nolines prehead(\begin{table}[hbt!]\centering 	\caption{@title} \label{tab:A19} \begin{tabular}{l*{6}{c}} \toprule)		///		
	posthead(\midrule)  prefoot(\midrule) ///
	postfoot(\bottomrule \end{tabular} \floatnote{Robust standard errors clustered at state level. Controls for Surplus Revenue disbursement, war, and time trend included in all models. All treatment and conditioning variables lagged by one year, except column 2 where outcome is lagged by three years.}	///
	\end{table}) substitute(\_ _) tex  fragment replace	

*** Figure A11: State level changes in revenues
graph combine logrev_CT logrev_NY logrev_VA logrev_RI logrev_NC logrev_SC, 	///
	xcommon ycommon  graphreg(col(white)) imargin(tiny) name(logrev, replace)
graph export "Figures\Supplemental\Supplemental-Figure-11.pdf", replace 

*** Figure A12: State level changes in expenditures
graph combine logexp_CT logexp_NY logexp_VA logexp_RI logexp_NC logexp_SC, 	///
	xcommon ycommon  graphreg(col(white)) imargin(tiny)	 name(logexp, replace)
graph export "Figures\Supplemental\Supplemental-Figure-12.pdf", replace 
	
